<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use app\modules\Order\models\OrderRoom;

$orderRoom = OrderRoom::findOne($room_id);


?>

<style type="text/css">
	.title{text-align: center;}
</style>

<body>
<div class="mui-content" style="background-color: #FFFFFF;">

	<div class="mui-row" style="padding:10px 5px;">

		<div class="mui-col-xs-12" style="border:1px solid #a664a6;padding:10px;background-color: #a664a6;color: #FFFFFF;">
		<?php if($orderRoom->order->product->stock == 1) {?> 

		<?= $orderRoom->productRoom->room->name ?> 
		<?= $orderRoom->productRoom->room->code ?>
		<?= $orderRoom->productRoom->people ?>人间
		<?php }elseif($orderRoom->order->product->stock == 2){ // 海外航线
			$t = json_decode($orderRoom->order->product->rooms, true);
			echo isset($t[$orderRoom->room_id]['name']) ? $t[$orderRoom->room_id]['name'] : '异常';
			echo "  - ".$orderRoom->num . "人";
		}
		?>
		<?php 
			$customers = $orderRoom->orderRoomCustomer;
			if($customers){
				foreach($customers as $c){
					//if($c->orderCustomer->status == 1){
					echo ' / '.$c->orderCustomer->first_name . $c->orderCustomer->last_name ; 
					//}	
				}	
			}
		?>
		</div>
	</div>

	<div class="mui-row header" style="padding: 15px;">
		<h4 class="title" style="">选择拼房订单</h4>
	</div>

	<div class="mui-row" style="font-size: 13px; border-radius:1px;padding: 5px;">
		<input type="hidden" id="order_id" value=<?= $model->id ?> >
		<input type="hidden" id="room_id" value=<?= $room_id ?> >
		<table style="width: 100%;margin-top: 10px;font-size: 0.9rem" border="1">

			<thead>
				<tr>
					<td class="mui-col-xs-3 title">联系人</td>
					<td class="mui-col-xs-3 title">订单信息</td>
					<td class="mui-col-xs-6 title"></td>
				</tr>
			</thead>

			<tbody>
			<?php foreach($data as $key=>$val){ ?>
			<tr>
				<td class="mui-col-xs-3 title">
					<?= $val->username ?> 
					<?= $val->phone ?>
				</td>
				<td class="mui-col-xs-3 title">	
					<?= $val->code ?>
					<span style="color:#FF4500;"><?= Yii::$app->formatter->asCurrency($val->price) ?></span>
				</td>
				<td class="mui-col-xs-6 title">
					<?php foreach($val->room as $room){ ?>
					<div class="mui-input-row mui-checkbox mui-left">
					 	<label><?php if($room->stock == 2){ ?>
							<i class="fa fa-remove"></i>	
						<?php } ?>
						<?php if($val->product->stock == 1) {?> 

							<?= $room->productRoom->room->name ?> 
							<?= $room->productRoom->room->code ?>
							<?= $room->productRoom->people ?>人间
						<?php }elseif($val->product->stock == 2){ // 海外航线
								$t = json_decode($val->product->rooms, true);
								echo isset($t[$room->room_id]['name']) ? $t[$room->room_id]['name'] : '异常';
								echo "  - ".$room->num . "人";
							}
						?>
						<?php 
								$customers = $room->orderRoomCustomer;
								if($customers){
									foreach($customers as $c){
										//if($c->orderCustomer->status == 1){
										echo ' / '.$c->orderCustomer->first_name . $c->orderCustomer->last_name ; 
										//}	
									}	
								}
						?></label>
					  	<input name="<?= $room->id?>"  class="magic-checkbox merge-magic" data-id=<?= $val->id ?> data-room=<?= $room->id ?>  <?= ($room->merge_id == $room_id) ? 'checked' : '' ?>  type="checkbox">
					</div>
					
					<?php } ?>
					</td>
			</tr>
			</tbody>
			<?php } ?>
		</table>
	</div>
</div>
</body>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">

    /**  add Loading  **/
    $(".merge-magic").click(function(){
        var order_id	= $("#order_id").val(); // 当前订单编号 
        var room		= $("#room_id").val();  // 当前需要拼房的房间ID

        var merge_id	= $(this).data('id');   // 待拼订单编号
        var room_id		= $(this).data('room');   // 待拼订单对应房型的编号

        var checked 	= $(this).is(':checked');   // 是否选中
		var t = $(this);
		//console.log(order_id);
		//console.log(merge_id);
		//console.log(room_id);
		//return;        
        $.get("/order/order/merge-save",{order_id:order_id, room:room, merge_id:merge_id, room_id:room_id, checked:checked},function(data){
			if(data == 'already_order'){
				alert("该订单已做过拼房, 每个订单只能做一次拼房");
				t.prop("checked", false);
			}else if(data == 'already_room'){
				alert("该房间已做过拼房, 每个房间只能做一次拼房");
				t.prop("checked", false);
			}
        });
    });

	
</script>
<?php app\components\JsBlock::end() ?>
